/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.shapes;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.*;
import java.util.ArrayList;

/**
 *
 * @author BIM1LA
 */
public class Shape_FV_Aqui implements JShape{
    
    
    double x_rel,y_rel,dx_rel,dy_rel,offset;
    Dimension dim;
    //int x, y;
    GeneralPath gp = null;
    Color color = Color.white;
    ArrayList<Double> aquip;
    boolean baqui = false;
    ArrayList<Double> aquil;
    int i;
    
    public Shape_FV_Aqui(Dimension dim,double offset, double x_rel, double y_rel, double dx_rel, double dy_rel, int i){
    
        this.offset = offset;
        this.x_rel = x_rel;
        this.y_rel = y_rel;
        this.dx_rel = dx_rel;
        this.dy_rel = dy_rel;
        this.dim = dim;
        this.i=i;
//        this.x = x;
//        this.y = y;
    
    }
    
    public double getx_rel(){return x_rel;}
    public double gety_rel(){return y_rel;}
    public Dimension getdim(){return dim;}
    public double getoffset(){return offset;}
    
    
    //public void updatedim(Dimension dim){this.dim = dim;}

    @Override
    public Rectangle getBounds() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Rectangle2D getBounds2D() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean contains(double x, double y) {

       return gp.contains(x, y);
        
    
    }

    @Override
    public boolean contains(Point2D p) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean intersects(double x, double y, double w, double h) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean intersects(Rectangle2D r) {
       return gp.intersects(r);
    }

    @Override
    public boolean contains(double x, double y, double w, double h) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean contains(Rectangle2D r) {
        
        return gp.contains(r);
        
    }

    @Override
    public PathIterator getPathIterator(AffineTransform at) {
        gp = new GeneralPath();
        
        double up,down,left,right;
        
        up = ((y_rel-dy_rel)*dim.height)+offset;
        down = ((y_rel+dy_rel)*dim.height)-offset;
        left = ((x_rel-dx_rel)*dim.width)-offset;
        right = ((x_rel+dx_rel)*dim.width)+offset;
         
        
//        gp.moveTo(left,up);
//        gp.lineTo(right,up);
//        gp.lineTo(right,down);
//        gp.lineTo(left,down);
//        gp.lineTo(left,up);
//        
//        gp.moveTo(left, up);
      
 
        
        
            paintaqui(gp, up, left, down, right);
        
        

        
        
        return gp.getPathIterator(at);
    }

    @Override
    public PathIterator getPathIterator(AffineTransform at, double flatness) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public Color getColor(){return color;}
    public void setColor(Color color){this.color=color;}
    
    public void setaquip(ArrayList<Double> aquip){this.aquip = aquip;} 
    public void setaquil(ArrayList<Double> aquil){this.aquil = aquil;} 
    public void setbaqui(boolean baqui){this.baqui = baqui;}
    
    public void paintaqui(GeneralPath gp, double up, double left, double down, double right){
    
    if(aquil!=null&&aquip!=null){
    
        int c = 0;
        
        double ol = aquip.get(0);
        double or = aquip.get(1);
        double ul = aquip.get(2);
        double ur = aquip.get(3);
        
//        if(ol != or && ol != ul && ol != ur){c++;}
//        if(or != ol && or != ul && or != ur){c++;}
//        if(ul != ol && ul != or && ul != ur){c++;}
//        if(ur != ol && ur != or && ul != ur){c++;}
        
        if(ol == or){c++;}
        if(ol == ul){c++;}
        if(ol == ur){c++;}
        if(or == ul){c++;}
        if(or == ur){c++;}
        if(ul == ur){c++;}
     
      //for(int i = 0; i < aquil.size(); i++){
          
          double tal = aquil.get(i);
       
          
          
          
            boolean moved = false;
                
                
                  if((ol <= tal && or >= tal) || (ol>=tal && or <= tal)){
                    double x1 = (tal-ol)/(or-ol);
                    gp.moveTo(left+x1*(right-left), up);
                    moved = true;
                    
                }

                if((or>=tal && ur <= tal) || (or<=tal && ur >= tal)){
                                       double x1 = (tal-or)/(or-ur);

                                       if(moved){
                                       
                                           gp.lineTo(right, up-x1*(down-up));
                                       
                                       }
                                       else{
                                       gp.moveTo(right, up-x1*(down-up));
                                       moved = true;
                                       }
                                       
                }
                
                 if((ur<=tal && ul >= tal)||(ur>=tal && ul <= tal)){
                    
                      double x1 = (tal-ul)/(ur-ul); 
                          if(moved){
                                       
                                           gp.lineTo(left+x1*(right-left), down);
                                       
                                       }
                                       else{
                                      gp.moveTo(left+x1*(right-left), down);
                                       moved = true;
                                       }
                     
                }

                if((ul>=tal && ol <= tal)||(ul<=tal && ol >= tal)){
                    double x1 = (tal-ol)/(ol-ul);
                    
                          
                                       
                                           gp.lineTo(left, up-x1*(down-up));
                                       
                                      
                    
                }
                
                
          
         /* 
        switch (c) {

            case 0:
                
                boolean moved = false;
                
//                if(ol <= tal && or >= tal){
//                    double x1 = (tal-ol)/(or-ol);
//                    gp.moveTo(left+x1*(right-left), up);
//                    moved = true;
//                    
//                }
//                else if(ol>=tal && or <= tal){
//                    
//                }
//                if(or>=tal && ur <= tal){
//                    System.out.println("3");
//                }
//                else if(or<=tal && ur >= tal){
//                    System.out.println("4");
//                }
//                 if(ur<=tal && ul >= tal){
//                     System.out.println("6");
//                }
//                else if(ur>=tal && ul <= tal){
//                     System.out.println("6");
//                }
//                if(ul>=tal && ol <= tal){
//                    System.out.println("7");
//                }
//                else if(ul<=tal && ol >= tal){
//                    System.out.println("8");
//                }
                
                  if((ol <= tal && or >= tal) || (ol>=tal && or <= tal)){
                    double x1 = (tal-ol)/(or-ol);
                    gp.moveTo(left+x1*(right-left), up);
                    moved = true;
                    
                }

                if((or>=tal && ur <= tal) || (or<=tal && ur >= tal)){
                                       double x1 = (tal-or)/(or-ur);

                                       if(moved){
                                       
                                           gp.lineTo(right, up-x1*(down-up));
                                       
                                       }
                                       else{
                                       gp.moveTo(right, up-x1*(down-up));
                                       moved = true;
                                       }
                                       
                }
                
                 if((ur<=tal && ul >= tal)||(ur>=tal && ul <= tal)){
                    
                      double x1 = (tal-ul)/(ur-ul); 
                          if(moved){
                                       
                                           gp.lineTo(left+x1*(right-left), down);
                                       
                                       }
                                       else{
                                      gp.moveTo(left+x1*(right-left), down);
                                       moved = true;
                                       }
                     
                }

                if((ul>=tal && ol <= tal)||(ul<=tal && ol >= tal)){
                    double x1 = (tal-ol)/(ol-ul);
                    
                          
                                       
                                           gp.lineTo(left, up-x1*(down-up));
                                       
                                      
                    
                }
                
                
               
                
                
                
                break;
            case 1:
 // zwei gleiche
            
                if(ol == ul){
                    System.out.println("olul");
                }
                if(ol == ur){
                    System.out.println("olur");
                }
                if(ol == or){
                    System.out.println("olor");
                }
                if(ul == ur){
                    System.out.println("ulur");
                }
                if(ul == or){
                    System.out.println("ulor");
                }
                if(ur == or){
                    System.out.println("uror");
                }
                
                
                
            case 2:
               
                if(ol == or && ul == ur){
                
                    System.out.println("links rechts");
                    
                }
                else if(ol == ul && or == ur){
                    
                  
                    
                    
                    
                    if(ol<=tal&&or>=tal){
                        
                        double x1 = (tal-ol)/(or-ol);
                        double x2 = (tal-ul)/(ur-ul);
                    
                        gp.moveTo(left+x1*(right-left), up);
                        gp.lineTo(left+x2*(right-left), down);
                        
                    }
                    else if(ol>=tal&&or<=tal){
                    }
                    
                    }
                
                
                
                
                break;
            case 3:
                System.out.println("3");
                break;
            case 4:
                System.out.println("4");
                break;
            default:
                System.out.println("bla");
                break;




        }*/
        
        
 
        
    
    //}
        
        
    }
    }
    
    
    
    public double getaquih(){return aquil.get(i);}
}
